#!/usr/bin/env python3
"""
简化的WebSocket测试脚本
"""

import asyncio
import websockets
import json

async def simple_test():
    """简单的连接测试"""
    uri = "ws://localhost:8080"
    
    try:
        print(f"连接到: {uri}")
        async with websockets.connect(uri) as websocket:
            print("连接成功！")
            
            # 发送简单的认证消息
            message = {
                "type": "AUTH",
                "data": {
                    "userId": "1",
                    "username": "test",
                    "userType": "USER",
                    "department": "test"
                }
            }
            
            print(f"发送消息: {json.dumps(message)}")
            await websocket.send(json.dumps(message))
            
            # 等待响应
            response = await asyncio.wait_for(websocket.recv(), timeout=5.0)
            print(f"收到响应: {response}")
            
    except asyncio.TimeoutError:
        print("连接超时")
    except Exception as e:
        print(f"错误: {e}")

if __name__ == "__main__":
    asyncio.run(simple_test()) 